package ren.kane.phoenix.some.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author renrk(1275) on 2018-11-02 11:05 AM
 **/
public class MyCallable implements Callable<Integer> {

    private int x = 5;
    private int y = 3;

    public MyCallable() {
    }

    public MyCallable(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public Integer call() throws Exception {
        return x + y;
    }

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService threadPool = Executors.newFixedThreadPool(2);
        MyCallable c1 = new MyCallable(100, 200);
        MyCallable c2 = new MyCallable(10, 20);

        Future<Integer> result = threadPool.submit(c1);
        Integer sum = result.get();
        System.out.println("sum=" + sum);

        result = threadPool.submit(c2);
        sum = result.get();
        System.out.println("sum=" + sum);
    }
}
